package dynamicTable

import (
	"project-info/src/handle/dynomicTable"
	"project-info/src/router/req"
	"project-info/src/router/variable"

	"github.com/gin-gonic/gin"
)

func init() {
	variable.InitRouteFunc = append(variable.InitRouteFunc, InitDynamicTableRoutes)
}

func InitDynamicTableRoutes(e *gin.Engine) {
	// 表格配置管理路由
	tableConfigGroup := req.NewGroup("/table-config").NeedToken().SetUpGroup(e)
	configReqs := []*req.Conf{
		req.NewPost("/save", dynomicTable.SaveTableConfig),
		req.NewGet("/get", dynomicTable.GetTableConfig),
		req.NewPost("/list", dynomicTable.ListTableConfig),
		req.NewPut("/update", dynomicTable.UpdateTableConfig),
		req.NewDelete("/delete", dynomicTable.DeleteTableConfig),
	}
	req.BatchSetUpRouter(tableConfigGroup, configReqs)

	// 动态表格数据管理路由
	dynamicDataGroup := req.NewGroup("/dynamic-table").NeedToken().SetUpGroup(e)
	dataReqs := []*req.Conf{
		req.NewPost("/data", dynomicTable.GetDynamicTableData),
		req.NewPost("/add", dynomicTable.AddDynamicTableData),
		req.NewPut("/update", dynomicTable.UpdateDynamicTableData),
		req.NewDelete("/delete", dynomicTable.DeleteDynamicTableData),
		req.NewGet("/options", dynomicTable.GetDynamicFieldOptions),
		req.NewPost("/privilege/bind", dynomicTable.BindDynamicPrivilege),
		req.NewPost("/privilege/get", dynomicTable.GetDynamicPrivilege),
	}
	req.BatchSetUpRouter(dynamicDataGroup, dataReqs)
}
